package common;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class DrawPanel extends JPanel implements MouseMotionListener{
	private int x,y; //绘制图像的位置坐标
	BufferedImage bimage; //将显示的图像
	public DrawPanel(Image image){
		addMouseMotionListener(this);
		
		//加载图片
		MediaTracker mt = new MediaTracker(this);
		mt.addImage(image,1);
		try{
		mt.waitForAll();
		}catch(Exception err){
		err.printStackTrace();
		}
		if (image.getWidth(this) == -1){
			System.exit(-1);
		}
		//创建缓冲区图像
		bimage = new BufferedImage(image.getWidth(this),image.getHeight(this),
		BufferedImage.TYPE_INT_ARGB);
		Graphics2D g2D = bimage.createGraphics();
		g2D.drawImage(image,0,0,this);
		
	}
	public void mouseDragged(MouseEvent e) {
		this.x = e.getX(); //重新设置位置
		this.y = e.getY();
		repaint();
	}

	public void mouseMoved(MouseEvent e) {
		
	}

}
